
<%@page import="ll.sms.util.SmsUtil,java.sql.*,java.util.Date"%><%@ page
	language="java"
	import="java.util.*,ll.sms.web.*,ll.sms.pojo.*,ll.sms.web.*,org.apache.commons.lang.*"
	pageEncoding="UTF-8"%>
<%@page import="ll.sms.util.AdminProperty"%>
<%
	try {
		SmsUser smsuser = new SmsUser();
		String currentUserName = SmsUtil.sessionHelper(session,AdminProperty.auname);
		String currentChannel =  SmsUtil.sessionHelper(session,AdminProperty.adefaultchannel);
		if(StringUtils.isBlank(currentChannel)){
			if("admin".equals(currentUserName)){
			out.print("{success:false,errors:{msg:'admin不允许创建用户'}}");
			return;
			}else{
				out.print("{success:false,errors:{msg:'未找到默认通道，请与管理员联系！'}}");
				return;
			}

		}
		
		String opuser = ParamUtils.getParameter(request,"auname");
		if(StringUtils.isBlank(opuser)){
		out.print("{success:false,errors:{msg:'未配置操作员'}}");
		return;
		}
		String pass = ParamUtils.getParameter(request, "upwd");
		String repass = ParamUtils.getParameter(request, "reupwd");
		if (pass == null || pass.trim().equals("")
				|| !pass.equals(repass)) {
			out.print("{success:false,errors:{msg:'密码不匹配..'}}");
			return;
		}

		RequestUtils.populate(smsuser, request);
		
		if(!SmsUtil.checkUsername(smsuser.getUuname())){
		out.print( "{success:false,errors:{msg:'用户名允许的字符为:英文字母、中文、下划线,长度为4-32位'}}");
		return;
		}
		
		smsuser.setUregisttime(new Timestamp(new Date().getTime()));
		smsuser.setUids(SmsUtil.getPrimaryKey());

		String uchannel = request.getParameter("uchannel");
		if(StringUtils.isBlank(uchannel)){
			out.print("{success:false,errors:{msg:'未给该用户配置通道'}}");
			return;
		}
		SmsOperator smsop = new SmsOperator();
		smsop.setOid(SmsUtil.getPrimaryKey());
		smsop.setOadminid(opuser);
		smsop.setOuserid(smsuser.getUids());
		out.print(WebBusinessImpl.getInstance().addUser(smsuser,smsop));
	} catch (Exception e) {
		e.printStackTrace();
		out.print("{success:false,errors:{msg:'添加失败！！'}}");
	}
	//out.print( "{success:true}");
%>
